import uni from "@dcloudio/vite-plugin-uni";
import vueJsx from "@vitejs/plugin-vue-jsx";
import {resolve} from "path";
import AutoImport from "unplugin-auto-import/vite";
import {defineConfig, PluginOption} from "vite";

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vitePlugin() // vite插件管理
    ],
    resolve: {
        alias: {
            "@": resolve(__dirname, "./src")
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                silenceDeprecations: ["legacy-js-api"] // 移出 【Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0】 警告
                // api: "modern-compiler"
            }
        }
    },
    define: {
        __VUE_I18N_FULL_INSTALL__: true,
        __VUE_I18N_LEGACY_API__: true,
        __INTLIFY_PROD_DEVTOOLS__: false
    }
});

// vite插件方法
function vitePlugin(): PluginOption
{
    return [
        uni(),
        vueJsx(),
        // 自动导入API
        AutoImport({
            // 自动导入 Vue 相关函数
            imports: ["vue", "uni-app", "pinia"],
            include: [
                /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
                /\.vue$/,
                /\.vue\?vue/ // .vue
            ],
            dirs: ["src/common", "src/mixin", "src/store/modules"],
            dts: "src/types/auto-imports.d.ts"
        })
    ];
}
